from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
from meiduo_mall import settings
def encrypt_openid(openid):
    # 给openid加密
    s = Serializer(secret_key=settings.SECRET_KEY,expires_in=600)
    access_token = s.dumps({'openid':openid})
    return access_token.decode()


from itsdangerous import SignatureExpired,BadSignature
def decode_openid(token):
    s = Serializer(secret_key=settings.SECRET_KEY, expires_in=600)
    try:
        result = s.loads(token)
    except BadSignature:
        return None

    return result.get('openid')